package com.jnu.hospitalexamination.controller;

import com.jnu.hospitalexamination.common.Result;
import com.jnu.hospitalexamination.entity.Hospital;
import com.jnu.hospitalexamination.service.HospitalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/hospital")
public class HospitalController {
    @Autowired
    private HospitalService hospitalService;

    @RequestMapping("/list")
    public Result getHospitalList() {
        return Result.success(200, "查询成功", hospitalService.list());
    }

    /**
     * 根据医院ID查询医院信息
     * @param hpId
     * @return
     */
    @RequestMapping("/getHospitalInfo")
    public Result getHospitalById(Integer hpId) {
        try {
            Hospital hospital = hospitalService.getById(hpId);
            return Result.success(200, "查询成功", hospital);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(500, "查询失败"+e.getMessage(), null);
        }
    }
}
